<template>
  <el-col class="commodity">
    <el-col class="title">认证列表</el-col>
    <el-col class="ct">
      <el-radio-group v-model="screen.type" @change="changera">
        <el-radio :label="1">已通过</el-radio>
        <el-radio :label="2">未审核</el-radio>
        <el-radio :label="3">未通过</el-radio>
      </el-radio-group>
    </el-col>
    <el-col class="list_table">
      <el-table
        :data="commodity_list"
        border
        stripe
        size="small"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column
          v-for="col in columns"
          :prop="col.id"
          :key="col.id"
          :label="col.label"
          :width="col.width"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column label="相关证明">
          <template slot-scope="scope">
            <!-- <template v-for="(item,index) in scope.row.certificate"> -->
            <span class="imags" @click="showMdel(scope.row.certificate)">
              <img :src="scope.row.certificate" alt srcset />
            </span>
            <!-- </template> -->
          </template>
        </el-table-column>
        <el-table-column label="认证状态" width="120">
          <template slot-scope="scope">
            <template v-if="scope.row.is_doctor===2">待审核</template>
            <template v-if="scope.row.is_doctor===1">已通过</template>
            <template v-if="scope.row.is_doctor===3">已拒绝</template>
          </template>
        </el-table-column>
        <el-table-column label="地区">
          <template slot-scope="scope">
            {{scope.row.doctor_province+scope.row.doctor_city}}
            <!-- <template v-if="scope.row.status===0">禁用</template>
            <template v-else>正常</template>-->
          </template>
        </el-table-column>
        <el-table-column label="操 作" min-width="220">
          <template slot-scope="scope">
            <!-- <el-button
              size="mini"
              @click.native.prevent="check(scope.$index,scope.row)"
              type="warning"
            >
              <i class="el-icon-edit-outline"></i>
              回复
            </el-button>-->
            <template v-if="scope.row.is_doctor==2">
              <el-button
                @click.native.prevent="editRow(scope.$index,scope.row,'yes')"
                type="primary"
                size="mini"
              >
                <i class="el-icon-edit-outline"></i>
                通过
              </el-button>

              <el-button
                @click.native.prevent="editRow(scope.$index,scope.row,'no')"
                type="warning"
                size="mini"
              >
                <i class="el-icon-error"></i>
                不通过
              </el-button>
            </template>
            <template v-if="scope.row.is_doctor==1">
              <el-button
                @click.native.prevent="editRow(scope.$index,scope.row)"
                type="danger"
                size="mini"
              >
                <i class="el-icon-error"></i>
                禁用
              </el-button>
            </template>
            <template v-if="scope.row.is_doctor==3">
              <el-button
                @click.native.prevent="editRow(scope.$index,scope.row)"
                type="danger"
                size="mini"
              >
                <i class="el-icon-error"></i>
                重新
              </el-button>
            </template>
          </template>
        </el-table-column>
      </el-table>
    </el-col>
    <el-col class="page">
      <el-col :span="5">
        <el-button type="warning" size="mini" @click="addlist">批量通过</el-button>
      </el-col>
      <el-pagination
        ref="pagination"
        layout="prev, pager, next"
        :total="total"
        @current-change="handleCurrentChange"
        :page-size="12"
        class="page_center"
      ></el-pagination>
    </el-col>
    <el-col class="dg">
      <el-dialog
        title="评论回复"
        :visible.sync="dialog"
        width="960px"
        @close="end"
        :modal-append-to-body="false"
      >
        <el-form :model="form" ref="form" label-width="80px" class="elf">
          <el-form-item label="回复评论">
            <el-input v-model="form.comment" type="textarea" :rows="3" placeholder="请输入回复评论内容"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="commentdata">立即回复</el-button>
            <!-- <el-button>取消</el-button> -->
          </el-form-item>
        </el-form>

        <span slot="footer">
          &nbsp;
          <!-- <el-button type="primary" @click="">确 定</el-button> -->
        </span>
      </el-dialog>
    </el-col>
    <el-dialog :visible.sync="el_dialog_show" :append-to-body="true" @close="end">
      <div class="modelimg">
        <img :src="this.dialogimg" alt srcset />
      </div>
      <span slot="footer">
        <el-button @click=" el_dialog_show= false">关闭</el-button>
        <!-- <el-button type="primary" @click="">确 定</el-button> -->
      </span>
    </el-dialog>
  </el-col>
</template>
<script>
export default {
  name: "commodity",
  data() {
    return {
      el_dialog_show: false,
      form: {
        comment: "" //回复评论参数
      },
      product_id: "",
      screen: {
        name: "",
        region: "",
        page: "",
        status: "",
        type: 2
      },
      page: "",
      dialogimg: "",
      commodity_list: [],
      columns: [
        {
          id: "nickName",
          label: "用户昵称",
          width: "100"
        },
        {
          id: "doctor_name",
          label: "姓名"
        },
        {
          id: "doct_phone",
          label: "电话",
          width: ""
        },

        {
          id: "hospital",
          label: "所属医院"
        }
      ],
      total: 0,
      dialog: false,
      datadetail: "",
      sh_radio: "2"
    };
  },
  mounted() {
    this.getlist();
  },
  methods: {
    showMdel(path) {
      //path
      this.el_dialog_show = true;
      this.dialogimg = path;
    },
    async getlist() {
      //获取商品列表
      let res = await this.$store.dispatch("doctorlist", this.screen);
      if (!res.code) {
        this.commodity_list = res.data.data;

        this.total = res.data.total;
      }
    },
    screenfn() {
      //筛选状态
      this.page = "";
      this.$refs.pagination.internalCurrentPage = 1;
      this.getlist();
    },
    async commentdata() {
      //回复评论
      let data = {
        product_id: this.product_id,
        content: this.form.comment
      };
      let res = await this.$store.dispatch("reply_product", data);
      if (!res.code) {
        this.$message({
          type: "success",
          message: "回复成功"
        });
        this.dialog = false;

        this.getlist();
      }
    },
    async editRow(index, row, su) {
      // product_id
      let data = {
        review_id: row.id,
        result: su
      };
      let res = await this.$store.dispatch("audit_doctorlist", data);
      if (row.code == 0) {
        this.$message({
          message: "操作成功",
          type: "success"
        });
      } else {
        this.$message({
          message: "操作失败",
          type: "error"
        });
      }
      if (!res.code) {
        this.getlist();
      }
    },
    async check(index, row) {
      //评论回复
      // console.log(index, row);
      this.product_id = row.id;
      this.dialog = true;

      //   let data = {
      //     com_id: row.id
      //   };
      //   let res = await this.$store.dispatch("getdetail_commodity", data);
      //   this.datadetail = res.data;
    },
    handleCurrentChange(val) {
      this.screen.page = val;
      this.getlist();
    },
    addlist() {
      //商品列表添加
      this.$confirm("确定要批量通过吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "删除成功!"
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    end() {
      //清空商品信息
      this.dialog = false;
      this.el_dialog_show = false;
      this.dialogimg = "";
    },
    handleSelectionChange(val) {
      console.log(val);
    },
    changera() {
      this.getlist();
    }
  }
};
</script>
<style lang="scss" scoped>
.elf {
  padding-top: 30px;
}
.imags {
  display: inline-block;
  width: 40px;
  height: 40px;
  overflow: hidden;
  margin: 0 5px;
  cursor: pointer;
  img {
    width: 40px;
    height: 40px;
  }
}
.ct {
  text-align: left;
}
.modelimg {
  width: 100%;
  img {
    width: 100%;
  }
}
</style>